var prothem = {};
prothem.csschange = function (css) {
  var style="";
  if(css.background){
    style +=prothem.changebg(css.background); 
  }
  if(css['border-radius']){
    style +=prothem.changeradius(css['border-radius']); 
  }
  if(css['box-shadow']){
    style +=prothem.changeshadow(css['box-shadow']); 
  }
  
  return style
}
prothem.changebg = function (bg) {
  var style="background:"
    if(bg['image']){
      style +="url('"+bg['image']+"') "
      style +=bg['x']+"% "+ bg['y'] +"% / "
      if(bg['size']=='custom'){
        style +=bg['w']+"% "+ bg['h'] +"% "
      }else{
        style +=bg['size'] +" ";
      }
    }
    style +=bg['repeat']+" ";
    if(bg['color']){
      style +=bg['color'];
    }
    if(!bg['color'] && !bg['image']){
      return "background:none;"
    }else{
      style +=";"
      return style
    }
}
prothem.changeradius = function (radius) {
  var style="border-radius:";
  var items=['top-left','top-right','bottom-right','bottom-left']
  items.forEach(element => {
    if(radius[element]){
      style +=radius[element]['val'] + radius[element]['unit'] +" ";
    }else{
      style += "0px ";
    }
  });
  style +=";"
  return   style
}
prothem.changeshadow = function (shadow) {
  var style="box-shadow:";
  if(shadow['isshow']==1){
    style +=shadow['color']+" "
    var items=['x','y','blur','spread']
    items.forEach(element => {
    if(shadow[element]){
      style +=shadow[element]['val'] + shadow[element]['unit'] +" ";
    }else{
      style += "0px ";
    }
  });
    if(shadow['type']=='in'){
      style +='inset'
    }
  }else{
    style +="none"
  }
  

  style +=";"
  return   style
}
module.exports = prothem